<?php

//include_once("inc/Task.php");

class ClientManager {
	public $clients = array();
	public $network;

	function __construct($network) {
		$this->network = $network;

		$data = "cmd=client_list\n";
		$this->network->send($data);
		$from = $this->network->recv();
//		echo "next: '$from'<br>\n";
		if(strpos($from, "client_list_reply") !== false) {
			$pm = new ParamManager();
			$pm->init($from, "|");
			$count = $pm->get("count");
			for($index = 0; $index < $count; $index ++) {
//				echo "index = $index, count = $count<br>\n";
				$from = $this->network->recv();
//				echo "next: '$from'<br>\n";

//				exit(0);
//				if($index == 0) {
//					exit(0);
//				}
				if(strpos($from, "client_list_item") !== false) {
					$pm->init($from, "|");
					$client = null;
					$client->host = $pm->get("host");
					$this->clients[] = $client;
				}
//				else {
//					// must be something else, like 'task_list_reply' or 'notice', ignore
//					$index --;
//				}
			}
		}
	}
}

?>
